using ns0;
using ns4;
using System;
namespace ns3
{
	internal sealed class Class3
	{
		private BitMatrix bitMatrix_0;
		private BitMatrix bitMatrix_1;
		private Version version_0;
		internal Class3(BitMatrix bitMatrix_2)
		{
			int dimension = bitMatrix_2.Dimension;
			if (dimension < 10 || dimension > 144 || (dimension & 1) != 0)
			{
				throw ReaderException.Instance;
			}
			this.version_0 = this.method_0(bitMatrix_2);
			this.bitMatrix_0 = this.method_8(bitMatrix_2);
			this.bitMatrix_1 = new BitMatrix(this.bitMatrix_0.Dimension);
		}
		internal Version method_0(BitMatrix bitMatrix_2)
		{
			Version versionForDimensions;
			if (this.version_0 != null)
			{
				versionForDimensions = this.version_0;
			}
			else
			{
				int dimension = bitMatrix_2.Dimension;
				int numColumns = dimension;
				versionForDimensions = Version.getVersionForDimensions(dimension, numColumns);
			}
			return versionForDimensions;
		}
		internal sbyte[] method_1()
		{
			sbyte[] array = new sbyte[this.version_0.TotalCodewords];
			int num = 0;
			int num2 = 4;
			int num3 = 0;
			int dimension = this.bitMatrix_0.Dimension;
			int num4 = dimension;
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			do
			{
				if (num2 == dimension && num3 == 0 && !flag)
				{
					array[num++] = (sbyte)this.method_4(dimension, num4);
					num2 -= 2;
					num3 += 2;
					flag = true;
				}
				else
				{
					if (num2 == dimension - 2 && num3 == 0 && (num4 & 3) != 0 && !flag2)
					{
						array[num++] = (sbyte)this.method_5(dimension, num4);
						num2 -= 2;
						num3 += 2;
						flag2 = true;
					}
					else
					{
						if (num2 == dimension + 4 && num3 == 2 && (num4 & 7) == 0 && !flag3)
						{
							array[num++] = (sbyte)this.method_6(dimension, num4);
							num2 -= 2;
							num3 += 2;
							flag3 = true;
						}
						else
						{
							if (num2 == dimension - 2 && num3 == 0 && (num4 & 7) == 4 && !flag4)
							{
								array[num++] = (sbyte)this.method_7(dimension, num4);
								num2 -= 2;
								num3 += 2;
								flag4 = true;
							}
							else
							{
								do
								{
									if (num2 < dimension && num3 >= 0 && !this.bitMatrix_1.get_Renamed(num3, num2))
									{
										array[num++] = (sbyte)this.method_3(num2, num3, dimension, num4);
									}
									num2 -= 2;
									num3 += 2;
								}
								while (num2 >= 0 && num3 < num4);
								num2++;
								num3 += 3;
								do
								{
									if (num2 >= 0 && num3 < num4 && !this.bitMatrix_1.get_Renamed(num3, num2))
									{
										array[num++] = (sbyte)this.method_3(num2, num3, dimension, num4);
									}
									num2 += 2;
									num3 -= 2;
								}
								while (num2 < dimension && num3 >= 0);
								num2 += 3;
								num3++;
							}
						}
					}
				}
			}
			while (num2 < dimension || num3 < num4);
			if (num != this.version_0.TotalCodewords)
			{
				throw ReaderException.Instance;
			}
			return array;
		}
		internal bool method_2(int int_0, int int_1, int int_2, int int_3)
		{
			if (int_0 < 0)
			{
				int_0 += int_2;
				int_1 += 4 - (int_2 + 4 & 7);
			}
			if (int_1 < 0)
			{
				int_1 += int_3;
				int_0 += 4 - (int_3 + 4 & 7);
			}
			this.bitMatrix_1.set_Renamed(int_1, int_0);
			return this.bitMatrix_0.get_Renamed(int_1, int_0);
		}
		internal int method_3(int int_0, int int_1, int int_2, int int_3)
		{
			int num = 0;
			if (this.method_2(int_0 - 2, int_1 - 2, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 2, int_1 - 1, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, int_1 - 2, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, int_1 - 1, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, int_1, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0, int_1 - 2, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0, int_1 - 1, int_2, int_3))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0, int_1, int_2, int_3))
			{
				num |= 1;
			}
			return num;
		}
		internal int method_4(int int_0, int int_1)
		{
			int num = 0;
			if (this.method_2(int_0 - 1, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, 2, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 2, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(1, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(2, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(3, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			return num;
		}
		internal int method_5(int int_0, int int_1)
		{
			int num = 0;
			if (this.method_2(int_0 - 3, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 2, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 4, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 3, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 2, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(1, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			return num;
		}
		internal int method_6(int int_0, int int_1)
		{
			int num = 0;
			if (this.method_2(int_0 - 1, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 3, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 2, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(1, int_1 - 3, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(1, int_1 - 2, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(1, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			return num;
		}
		internal int method_7(int int_0, int int_1)
		{
			int num = 0;
			if (this.method_2(int_0 - 3, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 2, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(int_0 - 1, 0, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 2, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(0, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(1, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(2, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			num <<= 1;
			if (this.method_2(3, int_1 - 1, int_0, int_1))
			{
				num |= 1;
			}
			return num;
		}
		internal BitMatrix method_8(BitMatrix bitMatrix_2)
		{
			int symbolSizeRows = this.version_0.SymbolSizeRows;
			int symbolSizeColumns = this.version_0.SymbolSizeColumns;
			if (bitMatrix_2.Dimension != symbolSizeRows)
			{
				throw new ArgumentException("Dimension of bitMarix must match the version size");
			}
			int dataRegionSizeRows = this.version_0.DataRegionSizeRows;
			int dataRegionSizeColumns = this.version_0.DataRegionSizeColumns;
			int num = symbolSizeRows / dataRegionSizeRows;
			int num2 = symbolSizeColumns / dataRegionSizeColumns;
			int dimension = num * dataRegionSizeRows;
			BitMatrix bitMatrix = new BitMatrix(dimension);
			for (int i = 0; i < num; i++)
			{
				int num3 = i * dataRegionSizeRows;
				for (int j = 0; j < num2; j++)
				{
					int num4 = j * dataRegionSizeColumns;
					for (int k = 0; k < dataRegionSizeRows; k++)
					{
						int int_ = i * (dataRegionSizeRows + 2) + 1 + k;
						int value = num3 + k;
						for (int l = 0; l < dataRegionSizeColumns; l++)
						{
							int int_2 = j * (dataRegionSizeColumns + 2) + 1 + l;
							if (bitMatrix_2.get_Renamed(int_2, int_))
							{
								int int_3 = num4 + l;
								bitMatrix.set_Renamed(int_3, value);
							}
						}
					}
				}
			}
			return bitMatrix;
		}
	}
}
